import { Component, OnInit, OnDestroy } from '@angular/core'
import { TitleService } from '@delon/theme'
import { ActivatedRoute } from '@angular/router'
import { DataService } from '@shared/services/data.service'
import {
  Task,
  ETaskType,
  ETaskStatus,
  ETaskCategory,
  ETaskOperation,
  ETaskPostRiskOperation,
} from '@shared/interfaces/task'
import { PageService } from '@shared/services/page.service'
import { Acquirer } from '@shared/interfaces/acquirer'
import { DashboardService } from '../../dashboard.abstract.service'
import { ACLService } from '@delon/acl'
import { CustomACLService } from '@shared/services/acl.service'
import { ECustomAcl, EColumnType } from '@shared/enums'

@Component({
  selector: 'app-todo-detail',
  templateUrl: './detail.component.html',
  styleUrls: ['./detail.component.less'],
})
export class DashboardTaskDetailComponent implements OnInit, OnDestroy {
  constructor(
    public titleService: TitleService,
    public pageService: PageService,
    private route: ActivatedRoute,
    private dataService: DataService,
    private dashboardService: DashboardService,
    private customACLService: CustomACLService,
    private aclService: ACLService,
  ) {}
  acquirer: Acquirer
  task: Task
  title = '任务详情'
  taskId: string
  taskCategory: string
  ETaskType = ETaskType
  ETaskStatus = ETaskStatus
  ETaskCategory = ETaskCategory
  ETaskOperation = ETaskOperation
  ETaskPostRiskOperation = ETaskPostRiskOperation

  ngOnInit() {
    this.taskId = this.route.snapshot.params['id']
    this.taskCategory = this.route.snapshot.params['type']
    this.dashboardService.getOne(this.taskId).subscribe(task => {
      this.task = task
      this.dataService.setTask(task)
    })
    this.setACL()
  }

  ngOnDestroy() {
  }

  setACL(): void {
    this.customACLService.removeACLAbility(ECustomAcl.StoreEditable)
  }

  checkTaskOperation(type: string): Boolean {
    for (const key in this.ETaskPostRiskOperation) {
      if (type === this.ETaskPostRiskOperation[key]) {
        return true
      }
    }
    return false
  }
}
